package com.count;

import com.count.number.SpecialNumber;
import com.count.rule.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ZhongGang
 * Date: 14-5-4
 * Time: 下午2:15
 */
public class CountGame {
    private List<Integer> numbers = new ArrayList<>();
    private List<SpecialNumber> specialNumbers = new ArrayList<>();
    private List<SpecialNumberRule> rules = new ArrayList<>();

    public CountGame(List<Integer> numbers, List<SpecialNumber> specialNumbers) {
        this.numbers = numbers;
        this.specialNumbers = specialNumbers;

        rules.add(new ContainFirstSpecialNumberRule());
        rules.add(new ContainMultipleSpecialNumberRule());
        rules.add(new TimesSpecialNumberRule());
        rules.add(new NormalSpecialNumberRule());
    }

    public List<String> count() {
        List<String> counts = new ArrayList<>();
        for (Integer number : numbers) {
            for (SpecialNumberRule rule : rules) {
                String result = rule.count(number, specialNumbers);
                if (result == null) {
                    continue;
                } else {
                    counts.add(result);
                    break;
                }
            }
        }
        return counts;
    }
}
